using PKGames.Audio;
using PKGames.SceneManagement;
using System;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
using VoxelEngine;
using VoxelGame;

namespace PKGames.MiniGames.VoxelGame.Scripts.World
{
	public class ResetProgressController : MonoBehaviour
	{
		[SerializeField]
		private Button _closeButton;

		[SerializeField]
		private Button _closeBgButton;

		[SerializeField]
		private Button _resetWorldButton;

		private Action _onClose;

		[CompilerGenerated]
		private static UnityAction _003C_003Ef__mg_0024cache0;

		public void SetupProgressController(Action closeBehaviour)
		{
			_onClose = closeBehaviour;
			_closeButton.onClick.RemoveAllListeners();
			_closeBgButton.onClick.RemoveAllListeners();
			_closeButton.onClick.AddListener(Close);
			_closeBgButton.onClick.AddListener(Close);
			_resetWorldButton.onClick.AddListener(DeleteSaveAsync);
		}

		private static void DeleteSaveAsync()
		{
			MonoSingleton<AudioManager>.Instance.Play("confirm");
			WorldSelectionConfig voxelPLayerData = BaseWorldController.VoxelPlayerData;
			Action onDisableAction = BaseWorldController.OnDisableAction;
			string worldId = BaseWorldController.VoxelPlayerData.VoxelWorldData.WorldId;
			PKGames.SceneManagement.TransitionController.SkipFadeout = true;
			MonoSingleton<SceneLoader>.Instance.GotoPreviousScene(delegate
			{
				DeleteSave(worldId);
				BaseWorldController.VoxelPlayerData = voxelPLayerData;
				BaseWorldController.OnDisableAction = onDisableAction;
				MonoSingleton<SceneLoader>.Instance.LoadSubScene("VoxelPlayer");
			});
            AdManager.ShowNative();
        }

		private static void DeleteSave(string worldId)
		{
			WorldSaveFileController.DeleteLocalSave(worldId);
		}

		private void Close()
		{
			_onClose.Fire();
            AdManager.ShowNative();
        }
	}
}
